using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.Serialization;
using System.Threading.Tasks;
using Azure;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.Extensions.Logging;
using ShopForWeb.Dtos.ViewModel;
using ShopForWeb.Services;
using ShopForWeb.UI.Utils.Filters;

namespace ShopForWeb.UI.Controllers.Test
{
  [Route("[controller]")]
  [UserInfo]
  public class ProductController : Controller
  {
    private readonly ILogger<ProductController> _logger;
    private ProductService _productServce;
    private CategoryService _categoryService;

    public ProductController(ILogger<ProductController> logger, ProductService productService,CategoryService categoryService)
    {
      _logger = logger;
      _productServce = productService;
       _categoryService= categoryService;
    }

    public async Task<IActionResult> IndexAsync([FromQuery] int page = 1, [FromQuery] int size = 16,[FromQuery] int statusCode = 0,
    [FromQuery]string key="",[FromQuery]long[] ids=null!)
    {
      var productList = await _productServce.GetByPageAsync(page, size, 1,key,ids);
      int total=await _productServce.GetTotalAsync(1,key,ids);
      var categoryList =await  _categoryService.GetAllAsync();
      ViewBag.ProductList=productList;
      ViewBag.CategoryList=categoryList;
      ViewBag.PageBar= new PageBarView(page,size,total);
      ViewBag.Key=key;
      ViewBag.Ids=(ids??[]).ToList();
       return View();
    }


  }
}